package cn.com.hhrcw.es.util;

import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
 * @author lixingxing
 */
@Slf4j
public class JobRefreshNoUtil {

    private JobRefreshNoUtil() {
    }

    /**
     * 创建job索引用刷新NO
     *
     * @param recommendNo
     * @param refreshNo
     * @param publishTime 已目前的逻辑来看，重建索引时有区别
     * @return
     */
    public static long createIndexRefreshNo(Integer recommendNo, Long refreshNo, Date publishTime) {
        log.info("recommendNo:{},refreshNo:{}", recommendNo, refreshNo);
        //        最小值：Long.MIN_VALUE=-9223372036854775808 （-2的63次方）
        //        最大值：Long.MAX_VALUE=9223372036854775807 （2的63次方-1）
        if (null == recommendNo) {
            recommendNo = 0;
        }
        //故意追加，避免0出现时未对其不好肉眼观察
        recommendNo++;

        if (null == refreshNo && null != publishTime) {
            log.info("refreshNo 参考 publishTime {}", publishTime);
            refreshNo = publishTime.getTime();
        }

        if (null == refreshNo) {
            refreshNo = System.currentTimeMillis();
        }

        final long indexRefreshNo = Long.parseLong(recommendNo + "" + refreshNo);
        log.info("indexRefreshNo:{} ", indexRefreshNo);

        return indexRefreshNo;

    }
}
